package ModelLayer;
import java.util.*;


/**
 * Write a description of class Order here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Order
{
    // instance variables - replace the example below with your own
    private int orderId;
    private String status;
    private String orderDate;
    private double totalPrice;
    private double discount;
    private ArrayList<PartOrder> partOrders;
    private DeliveryInfo deliveryInfo;
    private Person customer;
    private Employee salesman;
    private OrderType orderType;

    /**
     * Constructor for objects of class Order
     */
    public Order(int _orderId, String _status, String _orderDate, double _totalPrice, double _discount, DeliveryInfo _deliveryInfo, Person _customer, Employee _salesman, OrderType _orderType)
    {
        orderId = _orderId;
        status = _status;
        orderDate = _orderDate;
        totalPrice = _totalPrice;
        discount = _discount;
        deliveryInfo = _deliveryInfo;
        customer = _customer;
        salesman = _salesman;
        orderType = _orderType;
        partOrders = new ArrayList<PartOrder>();
    }
    
    public Order()
    {
        orderId = 0;
        status = "";
        orderDate = "";
        totalPrice = 0;
        discount = 0;
        deliveryInfo = null;
        customer = null;
        salesman = null;
        orderType = null;
        partOrders = new ArrayList<PartOrder>();   
    }
    
    public void setOrderDate(String _orderDate)
    {
        orderDate = _orderDate;
    }
    
    public void addPartOrder(PartOrder _partOrder)
    {
        partOrders.add(_partOrder);
    }
    
    public void setOrderId(int _orderId)
    {
        orderId = _orderId;
    }
    
    public void setStatus(String _status)
    {
        status = _status;
    }
    
    public void setEmployee(Employee _salesman)
    {
        salesman = _salesman;
    }
    
    public void setCustomer(Person _customer)
    {
        customer = _customer;
    }
    
    public void setOrderType(OrderType _orderType)
    {
        orderType = _orderType;
    }
    
    public void setDeliveryOrder(DeliveryInfo _deliveryInfo)
    {
        deliveryInfo = _deliveryInfo;
    }
    
    public void setTotalPrice(double _totalPrice)
    {
        totalPrice = _totalPrice;
    }
    
    public void setDiscount(double _discount)
    {
        discount = _discount;
    }
    
    public int getOrderId()
    {
        return orderId;
    }
    
    public String getOrderDate()
    {
        return orderDate;
    }
    
    public double getDiscount()
    {
        return discount;
    }
    
    public ArrayList<PartOrder> getAllPartOrders()
    {
        return partOrders;
    }
    
    public DeliveryInfo getDeliveryInfo()
    {
        return deliveryInfo;
    }
    
    public Person getCustomer()
    {
        return customer;
    }
    
    public Employee getEmployee()
    {
        return salesman;
    }
    
    public OrderType getOrderType()
    {
        return orderType;
    }
    
    public double getTotalPrice()
    {
        double _totalPrice = 0;
        
        for(PartOrder partOrder : partOrders)
        {
            double partOrderTotal = (partOrder.getQuantity() * partOrder.getProduct().getPurchasePrice());
            
            _totalPrice += partOrderTotal;
        }
        
        double calDiscount = totalPrice * (discount / 100);
        
        _totalPrice -= calDiscount;
        
        if(deliveryInfo != null)
        {
            _totalPrice += deliveryInfo.getDeliveryPrice();  
        }
        
        _totalPrice = _totalPrice;
        
        return _totalPrice;
    }
}
